package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuSerivce;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Reference
    MenuSerivce menuSerivce;

    @RequestMapping("/add")

    public Result add(@RequestBody Menu menu){

        menuSerivce.add(menu);

        return new Result(true, "添加菜单成功");

    }

    @RequestMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean){

        PageResult pageResult = menuSerivce.findByPage(queryPageBean);

        return new Result(true, "分页查询菜单成功", pageResult);
    }

    @RequestMapping("/findById")
    public Result findBYId(Integer id){
        Menu menu = menuSerivce.findById(id);
        return new Result(true,"根据id查询菜单成功",menu);
    }

    @RequestMapping("/edit")
    public Result edit(@RequestBody Menu menu) {
        menuSerivce.edit(menu);
        return new Result(true, "修改菜单成功");
    }

    @RequestMapping("/delById")
    public Result delById(Integer id) {
        menuSerivce.delById(id);
        return new Result(true,"删除菜单成功");
    }



}
